home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / Clueless.swf / scripts / org / flintparticles / counters / Steady.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  2.2 KB  |  96 lines

  1. package org.flintparticles.counters
  2. {
  3.    import org.flintparticles.emitters.Emitter;
  4.    
  5.    public class Steady implements Counter
  6.    {
  7.        
  8.       
  9.       private var _rateMax:Number;
  10.       
  11.       private var _stop:Boolean;
  12.       
  13.       private var _rateMin:Number;
  14.       
  15.       private var _timeToNext:Number;
  16.       
  17.       public function Steady(param1:Number, param2:Number = NaN)
  18.       {
  19.          super();
  20.          _stop = false;
  21.          _rateMin = param1;
  22.          _rateMax = isNaN(param2) ? param1 : param2;
  23.       }
  24.       
  25.       public function get rate() : Number
  26.       {
  27.          return _rateMin == _rateMax ? _rateMin : (_rateMax + _rateMin) * 0.5;
  28.       }
  29.       
  30.       public function set rateMin(param1:Number) : void
  31.       {
  32.          _rateMin = param1;
  33.       }
  34.       
  35.       public function stop() : void
  36.       {
  37.          _stop = true;
  38.       }
  39.       
  40.       public function startEmitter(param1:Emitter) : uint
  41.       {
  42.          _timeToNext = newTimeToNext();
  43.          return 0;
  44.       }
  45.       
  46.       public function resume() : void
  47.       {
  48.          _stop = false;
  49.       }
  50.       
  51.       public function get rateMin() : Number
  52.       {
  53.          return _rateMin;
  54.       }
  55.       
  56.       public function set rateMax(param1:Number) : void
  57.       {
  58.          _rateMax = param1;
  59.       }
  60.       
  61.       public function set rate(param1:Number) : void
  62.       {
  63.          _rateMax = _rateMin = param1;
  64.       }
  65.       
  66.       public function get rateMax() : Number
  67.       {
  68.          return _rateMax;
  69.       }
  70.       
  71.       private function newTimeToNext() : Number
  72.       {
  73.          var _loc1_:Number = NaN;
  74.          _loc1_ = _rateMin == _rateMax ? _rateMin : _rateMin + Math.random() * (_rateMax - _rateMin);
  75.          return 1 / _loc1_;
  76.       }
  77.       
  78.       public function updateEmitter(param1:Emitter, param2:Number) : uint
  79.       {
  80.          var _loc3_:uint = 0;
  81.          if(_stop)
  82.          {
  83.             return 0;
  84.          }
  85.          _loc3_ = 0;
  86.          _timeToNext -= param2;
  87.          while(_timeToNext <= 0)
  88.          {
  89.             _loc3_++;
  90.             _timeToNext += newTimeToNext();
  91.          }
  92.          return _loc3_;
  93.       }
  94.    }
  95. }
  96.